import { presetCategories } from '../src/renderer/features/text-assistant/stores/presetTemplates'

// 转换函数：将presetCategories转换为overlay格式
function convertToOverlayFormat(categories: any[]) {
  return categories.map(cat => {
    // 处理主分类
    const convertedCat: any = {
      id: cat.id,
      name: cat.name,
      icon: cat.icon,
      layout: cat.subcategories ? 'cards' : (cat.prompts ? 'single' : 'list'),
      description: cat.description
    }

    // 处理子分类
    if (cat.subcategories && Array.isArray(cat.subcategories)) {
      convertedCat.subcategories = cat.subcategories.map((subcat: any) => {
        return {
          id: subcat.id,
          name: subcat.name,
          icon: subcat.icon,
          subtitle: subcat.persona || '',
          // 添加user和system字段
          user: subcat.persona || '',
          system: subcat.prompts?.join('\n') || ''
        }
      })
    }

    // 处理prompts
    if (cat.prompts && Array.isArray(cat.prompts)) {
      convertedCat.prompts = cat.prompts
      // 添加user和system字段
      convertedCat.user = '',
      convertedCat.system = cat.prompts.join('\n')
    }

    return convertedCat
  })
}

// 生成categories.js文件内容
const overlayCategories = convertToOverlayFormat(presetCategories)

const fileContent = `// 将categories对象挂载到window对象上
window.categories = {
  "defaults": { "categoryId": "god-comment" },
  "categories": ${JSON.stringify(overlayCategories, null, 2)}
};`

// 写入文件
const fs = require('fs')
const path = require('path')

const outputPath = path.join(__dirname, '../android/app/src/main/assets/overlay/categories.js')
fs.writeFileSync(outputPath, fileContent)

console.log('categories.js generated successfully!')